package com.pmg;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.content.Intent;

public class Menu extends BaseGameActivity {
	private static final int CAMERA_WIDTH = 320;
	private static final int CAMERA_HEIGHT = 480;
	private static final int TEXTURE_WIDTH = 256;
	private static final int TEXTURE_HEIGHT = 256;

	private TextureRegion regionSplash;
	private BitmapTextureAtlas textureSplash;

	@Override
	public Engine onLoadEngine() {
		final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT,
				new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera));
	}

	@Override
	public void onLoadResources() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		this.textureSplash = new BitmapTextureAtlas(TEXTURE_WIDTH,
				TEXTURE_HEIGHT, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.regionSplash = BitmapTextureAtlasTextureRegionFactory
				.createFromAsset(this.textureSplash, this, "file_copy.png", 0,
						0);
		this.mEngine.getTextureManager().loadTexture(this.textureSplash);
	}

	@Override
	public Scene onLoadScene() {
		Scene scene = new Scene();
		Sprite spriteMan = new Sprite(10, 10, this.regionSplash);
		Thread th = new Thread() {
			@Override
			public void run() {
				int i = 0;
				while (true) {
					try {
						sleep(1000);
						if (i == 5) {
							Intent intent = new Intent(getApplicationContext(),
									Home.class);
							startActivity(intent);
						}
						i++;
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		};
		th.start();
		scene.attachChild(spriteMan);
		return scene;
	}

	@Override
	public void onLoadComplete() {
		// TODO Auto-generated method stub

	}

}